////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2010 Dimarik
//
////////////////////////////////////////////////////////////////////////////////

package
{

import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;

import ru.goodcore.core.QueryEvent;
import ru.goodcore.core.QueryLink;
import ru.goodcore.logging.Log;
import ru.goodcore.logging.LoggerLink;
import ru.goodcore.logging.targets.BuiltInDebugTarget;
import ru.goodcore.net.URI;
import ru.goodcore.transport.HTTPTransport;
import ru.goodcore.utils.ActivityListener;

/*
import ru.goodcore.core.composite.Branch;
*/

[SWF(frameRate='21',width='400',height='350',backgroundColor='0xD91189')]

public class TransportTest extends Sprite {

	/**
	 * Constructor 
	 */
	public function TransportTest() {
		super();		
		super.addEventListener(Event.ADDED_TO_STAGE, this.initialize);
	}

	private function initialize(event:Event):void {		
		super.stage.scaleMode = StageScaleMode.NO_SCALE;
		super.stage.align = StageAlign.TOP_LEFT;

		var performMeter:ActivityListener = new ActivityListener();
		super.stage.addChild(performMeter);

		this.startTest();
	}

	/**
	 * 
	 */
	private function startTest():void {
		var target:BuiltInDebugTarget = new BuiltInDebugTarget();
		target.formatter.includeMeasuredTime = true;
		Log.addTarget(target);
		super.stage.addChild(target);

		var firstLink:	QueryLink = new LoggerLink();
		firstLink.addEventListener(QueryEvent.QUERY_RESULT, this.handler_queryResult);

		//var secondLink:	QueryLink = new QueryLink();
		//firstLink.addChild(secondLink);

		var thirdLink:	QueryLink = new HTTPTransport();
		firstLink.addChild(thirdLink);
		
		var uri:URI = new URI('http://google.ru/');

		var request:Object = {
			uri		: uri
		}

		firstLink.perfomQuery(request);

	}


	private function handler_queryResult(event:QueryEvent):void {
		trace(event);
	}


}
}